﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.ChangeAlleyOwnerLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class ChangeAlleyOwnerLogEntry : LogEntry, IEncyclopediaLog, IChatNotification
  {
    [SaveableField(60)]
    public readonly Alley Alley;
    [SaveableField(61)]
    public readonly Hero NewOwner;

    internal static void AutoGeneratedStaticCollectObjectsChangeAlleyOwnerLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Alley);
      collectedObjects.Add((object) this.NewOwner);
    }

    internal static object AutoGeneratedGetMemberValueAlley(object o)
    {
      return (object) ((ChangeAlleyOwnerLogEntry) o).Alley;
    }

    internal static object AutoGeneratedGetMemberValueNewOwner(object o)
    {
      return (object) ((ChangeAlleyOwnerLogEntry) o).NewOwner;
    }

    public bool IsVisibleNotification => this.NewOwner != null && this.NewOwner == Hero.MainHero;

    public ChangeAlleyOwnerLogEntry(Alley alley, Hero newOwner, Hero oldOwner)
    {
      this.Alley = alley;
      this.NewOwner = newOwner;
    }

    public TextObject GetNotificationText() => this.GetEncyclopediaText();

    public override void GetConversationScoreAndComment(
      Hero talkTroop,
      bool findString,
      out string comment,
      out ImportanceEnum score)
    {
      score = ImportanceEnum.Zero;
      comment = "";
    }

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.Alley.Settlement || (object) obj == this.NewOwner;
    }

    public TextObject GetEncyclopediaText()
    {
      TextObject text;
      if (this.NewOwner != null)
      {
        text = GameTexts.FindText("str_alley_owner_changed_news");
        StringHelpers.SetCharacterProperties("HERO", this.NewOwner.CharacterObject, text);
      }
      else
        text = GameTexts.FindText("str_alley_cleared_news");
      text.SetTextVariable("SETTLEMENT", this.Alley.Settlement.EncyclopediaLinkWithName);
      text.SetTextVariable("COMMON_AREA", this.Alley.Name);
      return text;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();
  }
}
